function isvalidemail(str)
{
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (filter.test(str))
        return true;
    else
        return false;
}

function isEmail(s)
{
    if (s == "")
        return false;
    if (s.indexOf(" ") > 0)
        return false;
    if (s.indexOf("@") == -1)
        return false;
    var i = 1;
    var sLength = s.length;
    if (s.indexOf(".") == -1)
        return false;
    if (s.indexOf("..") != -1)
        return false;
    if (s.indexOf("@") != s.lastIndexOf("@"))
        return false;
    if (s.lastIndexOf(".") == s.length - 1)
        return false;
    var str = "0123456789abcdefghikjlmnopqrstuvwxyz-@._";
    for (var j = 0; j < s.length; j++)
        if (str.indexOf(s.charAt(j)) == -1)
            return false;
    return true;
}

function checkdate(s)
{
    var day;
    var month;
    var year;

    day = s.substring(0, 2);
    month = s.substring(3, 5);
    year = s.substring(6, 10);

    if (s.length < 10)
        return false;

    if (s.length > 10)
        return false;

    if ((month == 1) || (month == 3) || (month == 5) || (month == 7) || (month == 8) || (month == 10) || (month == 12))
    {
        if (day > 31)
            return false;
    }
    else
    if ((month == 4) || (month == 6) || (month == 9) || (month == 11))
    {
        if (day > 30)
            return false;
    }
    else
    {
        if (month == 2)
        {
            year = year % 4;

            if (year == 0)
            {
                if (day > 29)
                    return false;
            }
            else
            if (day > 28)
                return false;
        }
        else
            return false;

    }
    return true;
}


function isEmpty(s)
{
    return ((s == null) || (s.length == 0))
}

function isWhitespace(s)
{
    var whitespace = " \t\n\r";
    var i;

    if (isEmpty(s))
        return true;
    for (i = 0; i < s.length; i++)
    {
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1)
            return false;
    }
    return true;
}

function isNuber(c)
{
    return ((c >= "0" && c <= "9") || c == ".");
}

function isNubers(str)
{
    var isOK = true;
    for (var i = 0; i < str.length; i++)
    {
        if (!isNuber(str.charAt(i)))
        {
            isOK = false;
            break;
        }
    }
    return isOK;
}

function IsNumeric(VALUE) {
    for (var ivA = 0; ivA < VALUE.length; ivA++) {
        if (VALUE.charCodeAt(ivA) < 48 || VALUE.charCodeAt(ivA) > 57) {
            //if(VALUE.charCodeAt(ivA) != 46 && VALUE.charCodeAt(ivA) != 32 && VALUE.charAt(ivA) != ","){
            return false;
            //}
        }
    }
    return true;
}
//with . ,
function IsNumericReal(VALUE) {
    for (var ivA = 0; ivA < VALUE.length; ivA++) {
        if (VALUE.charCodeAt(ivA) < 48 || VALUE.charCodeAt(ivA) > 57) {
            if (VALUE.charAt(ivA) != "." && VALUE.charAt(ivA) != "," && VALUE.charAt(ivA) != "-") {
                return false;
            }
        }
    }
    return true;
}

function IsArray(MY_ARRAY) {
    MY_ARRAY = MY_ARRAY.constructor.toString();
    if (InStr(MY_ARRAY, "Array") > 0) {
        return true;
    }
    else {
        return false;
    }
}


function isNumber(obj) {
    var re = /^([0-9]*[0-9]$)/;
    var sNumber = obj.value;
    if (sNumber.search(re) == -1) {
        return false;
    }
    return true;
}

function filterNumber(nObj) {
    if (isNaN(nObj.value) || parseInt(nObj.value) <= 0) {
        nObj.value = "";
        nObj.focus();
        return;
    }
}

function checkform(form)
{
    if (form.value == "")
    {
        //alert("Please make sure all required fields (*) are entered.");
        form.focus();
        return false;
    }
    return true;
}

function myalert(content, divname)
{
    var divname = document.getElementById(divname);
    divname.innerHTML = content;
}

function mOvr(src, bgover) {
    src.style.cursor = 'hand';
    src.className = bgover;
}

function mOut(src, bgover) {
    src.style.cursor = 'default';
    src.className = bgover;
}

function mOvr2(src) {
    src.style.cursor = 'hand';
    src.bgColor = '#DBE1E7';
}

function mOut2(src) {
    src.style.cursor = 'default';
    src.bgColor = '#ECEFF2';
}

function docheckallnew(chked, src) {
    var alen = src.length;
    if (alen > 0) {
        for (var i = 0; i < alen; i++)
            src[i].checked = chked;
    }
    else {
        src.checked = chked;
    }
}

function selectid(src) {
    var strchon = "";
    var alen = src.length;
    if (alen > 0) {
        for (var i = 0; i < alen; i++)
            if (src[i].checked == true)
                strchon += src[i].value + ",";
    }
    else {
        if (src.checked == true)
            strchon = src.value + ",";
    }
    return strchon;
}

function docheckall(srcall, src) {
    var chked = srcall.checked;
    var alen = src.length;
    if (alen > 0) {
        for (var i = 0; i < alen; i++)
            src[i].checked = chked;
    }
    else {
        src.checked = chked;
    }
}

function docheckone(srcall, src) {
    var ischecked = true;
    var alen = src.length;
    if (alen > 0) {
        for (var i = 0; i < alen; i++)
            if (src[i].checked == false)
                ischecked = false;

    }
    else {
        if (src.checked == false)
            ischecked = false;
    }
    srcall.checked = ischecked;
}

function AddTo(srcobj, desobj)
{
    if (srcobj.selectedIndex > -1) {
        var i = 0;
        while (i < srcobj.length) {
            if (srcobj[i].selected == true) {
                var objOption = document.createElement("OPTION");
                desobj.options.add(objOption);
                objOption.innerHTML = srcobj[i].text;
                objOption.value = srcobj[i].value;
                srcobj.remove(i);
            }
            else
                i++;
        }
//        SortItem(srcobj);
//        SortItem(desobj);
    }
}

function SaveID(obj)
{
    var strid = "";
    var num = obj.options.length;
    if (num > 0) {
        for (var i = 0; i < num; i++) {
            strid += obj.options[i].value + ",";
        }
    }
    return strid;
}

function SortItem(obj)
{
    var num = obj.options.length;
    var i, j = 0;
    var anArrayValue = new Array(num + 1);
    var anArrayText = new Array(num + 1);
    for (i = 0; i < num; i++) {
        anArrayText[i] = obj[i].text;
        anArrayValue[i] = obj[i].value;
    }
    var valueTemp = "";
    var textTemp = "";
    for (i = 0; i < num; i++) {
        textTemp = anArrayText[i];
        valueTemp = anArrayValue[i];
        for (j = i + 1; j < num; j++) {
            if (anArrayText[j] < textTemp) {
                anArrayText[i] = anArrayText[j];
                anArrayText[j] = textTemp;
                anArrayValue[i] = anArrayValue[j];
                anArrayValue[j] = valueTemp;
                valueTemp = anArrayValue[i];
                textTemp = anArrayText[i];
            }
        }
    }
    for (i = num - 1; i >= 0; i--) {

        obj.remove(i);
    }
    for (i = 0; i < num; i++) {
        var oOption = document.createElement("OPTION");
        obj.options.add(oOption);
        oOption.innerHTML = anArrayText[i];
        oOption.value = anArrayValue[i];
    }
}

function changedate(s)
{
    var day;
    var month;
    var year;
    var cdate;
    day = s.substring(0, 2);
    month = s.substring(3, 5);
    year = s.substring(6, 10);
    cdate = month + "-" + day + "-" + year;
    return cdate;
}

function toggleDisplay(id) {
    if (this.document.getElementById(id).style.display == 'none') {
        this.document.getElementById(id).style.display = ''
        if (this.document.getElementById(id) != undefined) {
            this.document.getElementById(id).style.display = 'none';
        }
    }
    else {
        this.document.getElementById(id).style.display = 'none'
        if (this.document.getElementById(id) != undefined) {
            this.document.getElementById(id).style.display = '';
        }
    }
}

function explorer(iself, pathplus, pathsub, spanid) {
    if (iself.src.lastIndexOf(pathplus) == iself.src.length - pathplus.length) {
        iself.src = pathsub;
        document.getElementById(spanid).style.display = '';
    }
    else {
        iself.src = pathplus;
        document.getElementById(spanid).style.display = 'none';
    }
}

function changeColor(panel)
{
    var panels = ['aaa', 'bbb', 'ccc', 'ddd'];
    for (var i = 0; i < panels.length; i++)
    {

        if (panel == panels[i])
        {
            console.log(panels[i]);
            if (document.getElementById(panels[i]).className == "lienket1")
                document.getElementById(panels[i]).className = "lienket";
            else
            {
                if (document.getElementById(panels[i]))
                    document.getElementById(panels[i]).className = "lienket1";
                if (document.getElementById(panels[i] + '_s'))
                    document.getElementById(panels[i] + '_s').style.display = 'block';
            }
        }
        else
        {
            if (document.getElementById(panels[i]))
                document.getElementById(panels[i]).className = "lienket";
            if (document.getElementById(panels[i] + '_s'))
                document.getElementById(panels[i] + '_s').style.display = 'none';

        }

    }
}

function changeColor_02(panel)
{
    var panels = ['aaaa', 'bbbb', 'cccc', 'dddd'];
    for (var i = 0; i < panels.length; i++)
    {
        if (panel == panels[i])
        {
            if (document.getElementById(panels[i]).className == "lienket1")
                document.getElementById(panels[i]).className = "lienket";
            else
            {
                document.getElementById(panels[i]).className = "lienket1";
                document.getElementById(panels[i] + '_s').style.display = 'block';
            }
        }
        else
        {

            document.getElementById(panels[i]).className = "lienket";
            document.getElementById(panels[i] + '_s').style.display = 'none';

        }
    }
}

function changeColor_03(panel)
{
    var panels = ['aaaaa', 'bbbbb', 'ccccc', 'ddddd'];
    for (var i = 0; i < panels.length; i++)
    {
        if (panel == panels[i])
        {
            if (document.getElementById(panels[i]).className == "lienket1")
                document.getElementById(panels[i]).className = "lienket";
            else
            {
                document.getElementById(panels[i]).className = "lienket1";
                document.getElementById(panels[i] + '_s').style.display = 'block';
            }
        }
        else
        {

            document.getElementById(panels[i]).className = "lienket";
            document.getElementById(panels[i] + '_s').style.display = 'none';

        }
    }
}


function changeColor_04(panel)
{
    var panels = ['aaaaaa', 'bbbbbb', 'cccccc', 'dddddd'];
    for (var i = 0; i < panels.length; i++)
    {
        if (panel == panels[i])
        {
            if (document.getElementById(panels[i]).className == "lienket1")
                document.getElementById(panels[i]).className = "lienket";
            else
            {
                document.getElementById(panels[i]).className = "lienket1";
                document.getElementById(panels[i] + '_s').style.display = 'block';
            }
        }
        else
        {

            document.getElementById(panels[i]).className = "lienket";
            document.getElementById(panels[i] + '_s').style.display = 'none';

        }
    }
}


function changeColor_05(panel)
{
    var panels = ['aaaaaaa', 'bbbbbbb', 'ccccccc', 'ddddddd'];
    for (var i = 0; i < panels.length; i++)
    {
        if (panel == panels[i])
        {
            if (document.getElementById(panels[i]).className == "lienket1")
                document.getElementById(panels[i]).className = "lienket";
            else
            {
                document.getElementById(panels[i]).className = "lienket1";
                document.getElementById(panels[i] + '_s').style.display = 'block';
            }
        }
        else
        {

            document.getElementById(panels[i]).className = "lienket";
            document.getElementById(panels[i] + '_s').style.display = 'none';

        }
    }
}

$(document).ready(function() {
    if ($('input.checkall')) {
        $('input.checkall').click(function() {
            if ($(this).is(':checked')) {
                console.log('1');
                $(this).closest('form').find('tbody input[type="checkbox"]').prop("checked", true);
                ;
            } else {
                console.log('2');
                $(this).closest('form').find('tbody input[type="checkbox"]').prop("checked", false);
                ;
            }
        });
    }
});

